
import 'package:flutter_comm_base_framework/core/utils/string_utils.dart';
import 'package:intl/intl.dart';

class TimeUtils{
  static String getCurrentTime(){
    return DateFormat("yyyy-MM-dd HH:mm:ss").format(DateTime.now());
  }

  static String getCurrentDate(){
    return DateFormat("yyyy-MM-dd").format(DateTime.now());
  }

  static String getTimeString(DateTime dateTime,{String format="yyyy-MM-dd HH:mm:ss"}){
    return dateTime == null ? "":DateFormat(format).format(dateTime);
  }

  static DateTime getDateTime(String dateTime){
    if(dateTime == null || dateTime.length<1){
      return null;
    }
    return DateTime.parse(dateTime);
  }



  /// createTime  yyyy-MM-dd HH:mm:ss
  /// waitTime 秒
  static String getLastTime4Format(String createTime,int waitTime){
    String ss = "00:00:00";
    int time = DateTime.parse(createTime).millisecondsSinceEpoch + waitTime*1000 - DateTime.now().millisecondsSinceEpoch;
    ss = StringUtils.secToTime(time~/1000);

    return ss;
  }

  /// createTime  yyyy-MM-dd HH:mm:ss
  /// waitTime 秒
  ///返回等待倒计时的时间　　毫秒级
  static int getLastTime(String createTime,int waitTime){
    return DateTime.parse(createTime).millisecondsSinceEpoch + waitTime*1000 - DateTime.now().millisecondsSinceEpoch;
  }
}